package middleware

import (
	"time"

	"go-gin-api/internal/pkg/core"
)

const (
	ttl       = time.Minute * 2 // 签名超时时间 2 分钟
	minLength = 2               // split space 最小长度
	notUsed   = -1              // -1 表示被禁用

)

var whiteListPath = map[string]bool{
	"/login/web": true,
}

func (m *middleware) Signature() core.HandlerFunc {
	return func(c core.Context) {
		/*
			// 签名信息
			authorization := c.GetHeader(configs.HeaderSignToken)
			if authorization == "" {
				c.AbortWithError(errno.NewError(
					http.StatusBadRequest,
					code.Text(code.AuthorizationError)).WithErr(errors.New("Header 中缺少 Authorization 参数")),
				)
				return
			}

			// 时间信息
			date := c.GetHeader(configs.HeaderSignTokenDate)
			if date == "" {
				c.AbortWithError(errno.NewError(
					http.StatusBadRequest,
					code.Text(code.AuthorizationError)).WithErr(errors.New("Header 中缺少 Date 参数")),
				)
				return
			}

			// 通过签名信息获取 key
			authorizationSplit := strings.Split(authorization, " ")
			if len(authorizationSplit) < minLength {
				c.AbortWithError(errno.NewError(
					http.StatusBadRequest,
					code.Text(code.AuthorizationError)).WithErr(errors.New("Header 中 Authorization 格式错误")),
				)
				return
			}

			key := authorizationSplit[0]

			fmt.Println("key" + key)
		*/

	}
}
